---
title: "TP PULSACIONES DEL MOUSE Y DEL TECLADO"
author: "ADRIAN PABLO CAFA"
output:
flexdashboard::flex_dashboard:
orientation: rows
social: menu
source_code: embed
---
```{r setup, include=FALSE}
library(dygraphs)
library(xts) # To make the convertion data-frame / xts format
library(tidyverse)
library(lubridate)
library(manipulateWidget)
library(htmlwidgets)
library(treemap)
library(xlsx)
library(xtable)
library(dplyr)
library(d3treeR)
library(d3Tree)
library(ggplotlyExtra)
library(plotly)
# Read the data
data1 <- read.table("C:/Users/ADRIAN CAFA/Desktop/bd_tp_final/mouse_y_teclado_totales.csv", header=T, sep=",") %>% head(15)
# Check type of variable
# str(data)
# Since my time is currently a factor, I have to convert it to a date-time format!
data1$datetime <- ymd_hms(data1$datetime)
# Then you can create the xts necessary to use dygraph
don1 <- xts(x = data1$Clicks, order.by = data1$datetime)
don2 <- xts(x = data1$Keys, order.by = data1$datetime)
data2 <- read.xlsx("C:/Users/ADRIAN CAFA/Desktop/bd_tp_final/teclas_pulsadas_semanalmente.xlsx", sheetIndex = 1)
#Convert numeric columns to a numeric data type
data2$Keycount <- as.numeric(data2$Keycount)
data3 <- read.xlsx("C:/Users/ADRIAN CAFA/Desktop/bd_tp_final/teclas_pulsadas_semanalmente4.xlsx", sheetIndex = 1)
char_frequencies <- as.data.frame(data3)
char_frequencies$Freq
char_frequencies$Freq <- char_frequencies$Freq * 100/sum(char_frequencies$Freq)
treemap <- treemap(data2, #Your data frame object
index=c("Keyname"), #A list of your categorical variables
vSize = "Keycount", #This is your quantitative variable
type="index", #Type sets the organization and color scheme of your treemap
palette = "Reds" #Select your color palette from the RColorBrewer presets or make your own.
)
```
Gráficos
=======================================================================
Row
-----------------------------------------------------------------------
### Clicks-mouse
```{r}
p1 <- dygraph(don1) %>%
dySeries("V1", label = "Clicks-mouse") %>%
dyOptions(labelsUTC = TRUE, fillGraph=TRUE, fillAlpha=0.1, drawGrid = FALSE, colors="#D8AE5A") %>%
dyRangeSelector() %>%
dyCrosshair(direction = "vertical") %>%
dyHighlight(highlightCircleSize = 5, highlightSeriesBackgroundAlpha = 0.2, hideOnMouseOut = FALSE)
myWidget1 <- combineWidgets(p1)
myWidget1
```
### Keys-keyboard
```{r}
don2 <- xts(x = data1$Keys, order.by = data1$datetime)
p2 <- dygraph(don2) %>%
dySeries("V1", label = "Keys-keyboard") %>%
dyOptions(labelsUTC = TRUE, fillGraph=TRUE, fillAlpha=0.1, drawGrid = FALSE, colors="#D8AE5A") %>%
dyRangeSelector() %>%
dyCrosshair(direction = "vertical") %>%
dyHighlight(highlightCircleSize = 5, highlightSeriesBackgroundAlpha = 0.2, hideOnMouseOut = FALSE)
myWidget2 <- combineWidgets(p2)
myWidget2
```
Row
-----------------------------------------------------------------------
### TreeMap of keyboards keys usage
```{r}
p3 <- d3tree2( treemap)
myWidget3 <- combineWidgets(p3)
myWidget3
```
### % letters keys usage
```{r}
cloud <- ggplot(char_frequencies, aes(x=split_letters, y = Freq)) +
geom_point(size = 6) +
geom_segment(aes(x=split_letters, y = 0, xend = split_letters, yend = Freq), size = 1.1) +
theme_classic() +
geom_hline(yintercept = 0) +
geom_text(aes(label = split_letters), colour = "white", nudge_y = 0.05) +
labs(y = "% letters frequency") +
# coord_flip() +
theme(axis.line.x = element_blank(), axis.text.x = element_blank(), axis.ticks.x = element_blank(), axis.title.x = element_blank())
cloud <- ggplotly(autosize = F)
cloud
```